package bishi._58tongcheng;

import java.util.Arrays;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2021/09/25 19:24
 */
public class one {
    public static void main(String[] args) {
        one one = new one();
        System.out.println(one.weight(new int[]{2}, 3));
    }
    public int weight (int[] weights, int total) {
        // write code here
        Arrays.sort(weights);
        int[] dp = new int[total+1];
        dp[total] = 0;
        for(int i=total;i>0;i--){
            for(int j =0;j<weights.length&&weights[j]<=i;j++){
                if (i!=total&&dp[i]==0){
                    continue;
                }
                dp[i-weights[j]] = dp[i-weights[j]]>0?Math.min(dp[i-weights[j]],dp[i]+1):(dp[i]+1);
            }
        }
        return dp[0]==0?-1:dp[0];
    }
}
